import http from "@/api";
import { ResPage, User } from "@/api/interface/index";
import { showMsg } from "@/utils/util";

/**
 * @name 用户管理模块
 */
// * 获取用户列表
export const getUserList = (params: any) => {
	return http.get<ResPage<User.ResUserList>>(`/user/find`, params);
};

// * 新增用户
export const addUser = (params: any) => {
	return http.post(`/user/add`, params);
};

// * 编辑用户
export const editUser = (params: any) => {
	return http.post(`/user/modify`, params);
};

// * 删除用户
export const deleteUser = (params: { id: string; ids?: string }) => {
	return http.post(`/user/remove`, params);
};
// * 获取用户信息
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const getUser = (username?: string) => {
	return http.get<User.ResUserList>(`/user/get${username ? "?username=" + username : ""}`);
	// return http.get<User.ResUserList>(`/user/get?username=${username || ""}`);
};
// * 重置当前登录用户密码
export const resetUserPassWord = (params: { username: string }) => {
	return http.post(`/user/password/reset`, params);
};
// * 确认用户密码
export const checkUserPassWord = (params: { username: string; password: string }) => {
	return http.get(`/user/password/check`, params);
};
// * 修改用户密码
export const modifyUserPassWord = (params: { username: string; password: string; newPassword: string }) => {
	return http.post(`/user/password/modify`, params);
};
//用户注册
export const register = (params: User.ReqUserRegister) => {
	return http.post(`/auth/register`, params);
};
//获取注册验证码
export const getPhoneCode = (params: { identifier: string }) => {
	return http.get(`/auth/verify-code/get`, params);
};
//忘记密码进行重置
export const resetUserPassWord2 = (params: { username: string; mobile: string; password: string; code: string }) => {
	return http.post(`/auth/reset-password-by-phone`, params);
};
//获取注册验证码
export const checkUserExists = (params: { username?: string; mobile?: string; email?: string }) => {
	let form: { username: string } = { username: "" };
	if (params.username) {
		form.username = params.username;
	} else if (params.mobile) {
		form.username = params.mobile;
	} else if (params.email) {
		form.username = params.email;
	} else {
		showMsg("用户名不能为空", false);
		return;
	}
	return http.get<User.ResUserList>(`/auth/user-exist`, form);
};

// 获取所有菜单
export const getAllMenuList = (param?: { [key: string]: any }) => {
	return http.get<Menu.MenuOptionsRows>(
		`/menu/find`,
		{ pageSize: 9999, pageIndex: 1, enable: 0, ...param },
		{ headers: { noLoading: true } }
	);
};
//查询租户logo和系统名称
export const getLogo = (param?: { [key: string]: any }) => {
	return http.get<any>(`/sys/logo/get`, param);
};
//保存租户logo和系统名称
export const saveLogo = (params: any) => {
	return http.post(`/sys/logo/save`, params);
};
